#include <bits/stdc++.h>
using namespace std;
int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int isLeap(int y) {
  if (y % 400 == 0 || y % 4 == 0 && y % 100 != 0)
    return 1;
  else
    return 0;
}
int main() {
  int y, m, d, h, k;
  cin >> y >> m >> d >> h >> k;
  if (isLeap(y))
    days[2] = 29;

  h = h + k;
  d = d + h / 24;
  h = h % 24;

  if (d > days[m]) {
    m++;
    d -= days[m];
  }
  if (m > 12) {
    y++;
    m -= 12;
  }
  cout << y << " " << m << " " << d << " " << h;
  return 0;
}